export function mapFun (map, datalist) {
  map.clearMap()
  function createInfoWindow (data) {
    let content = `
      <div style='width: 23.875rem;background: url(${process.env.BASE_URL}img/04.png) no-repeat;background-size: 100% 100%;padding:2rem'>
        <p class="font_s20 colorF">${data.mc}</p>
        <p>
          <img class="verticM" style="height:1.125rem;" src="${process.env.BASE_URL}img/05.png" alt="">&nbsp;&nbsp;
          <span class="Bold font_s16" style="color:#28A1FF">${data.dz} </span>
        </p>
        <p>
          <span class="Bold font_s16" style="color:#B0D5ED">法人代表：${data.fddbr}</span>
        </p>
        <p>
          <span class="Bold font_s16" style="color:#B0D5ED">成立日期：${data.clrq}</span>
        </p>
      </div>
    `
    // <p class="font_s18" style="color: #5AD834;padding-left: 3rem;"><span>公墓生命周期图</span></p>
    var info = document.createElement('div')
    info.className = 'custom-info input-card content-window-card'

    var middle = document.createElement('div')
    middle.className = 'info-middle'
    // middle.style.backgroundColor = 'rgba(2,17,64,0.87)'
    middle.innerHTML = content
    info.appendChild(middle)
    return info
  }
  // 创建点
  // console.log(datalist)
  for (const elem of datalist.values()) {
    let arr = []
    arr.push(elem.jg)
    arr.push(elem.wd)
    elem.lnglat = arr
  }
  let infoWindow = new AMap.InfoWindow({ isCustom: true, offset: new AMap.Pixel(0, -30) })
  for (let i = 0, marker; i < datalist.length; i++) {
    marker = new AMap.Marker({
      position: datalist[i].lnglat,
      icon: `${process.env.BASE_URL}img/0${datalist[i].zzlx}.png`,
      map: map
    })
    marker.content = createInfoWindow(datalist[i])
    marker.on('click', markerClick)
    marker.emit('click', { target: marker })
  }
  function markerClick (e) {
    infoWindow.setContent(e.target.content)
    if (e.pixel) { // 初始不打开弹窗
      infoWindow.open(map, e.target.getPosition())
    }
  }
  map.setFitView()
};
